package com.im.service.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.im.service.common.Result;
import com.im.service.domain.entity.ImUser;
import com.im.service.domain.vo.UserVO;
import com.im.service.service.ImUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * im-用户 前端控制器
 * </p>
 *
 * @author 刘志强
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/imUser")
@CrossOrigin
@Slf4j
@Api(tags = "IM用户相关接口")
public class ImUserController {

    @Autowired
    private ImUserService userService;

    @PostMapping("/register")
    @ApiOperation(value = "注册")
    public Result register(@RequestBody ImUser imUser) {
        return userService.register(imUser);
    }

    @GetMapping("/getUnread")
    @ApiOperation(value = "获取未读")
    public Result<Integer> getUnread() {
        Long userId = StpUtil.getLoginIdAsLong();
        return userService.getUnread(userId);
    }

    @GetMapping("/userList")
    @ApiOperation(value = "用户列表")
    public Result<List<ImUser>> userList() {
        return userService.userList();
    }

    @GetMapping("/userMap")
    @ApiOperation(value = "用户Map")
    public Result<Map<String, ImUser>> userMap() {
        return userService.userMap();
    }

    @GetMapping("/userInfo")
    @ApiOperation(value = "用户详情")
    public Result<UserVO> userInfo(Long id) {
        return userService.userInfo(id);
    }

    @GetMapping("/getCurrentUser")
    @ApiOperation(value = "用户详情")
    public Result<UserVO> getCurrentUser() {
        Long id = StpUtil.getLoginIdAsLong();
        return userService.userInfo(id);
    }
}
